package com.xiongwei.manageback.config;

import com.xiongwei.manageback.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor())
                .addPathPatterns("/**")
//                不拦截的接口,注意：只从controller层开始配置路径即可，忽略配置文件中的前置路径
                .excludePathPatterns("/user/login",
                        "/user/register",
                        "/user/sendCode",
                        "/user/sendEmailCode",
                        "/file/upload",
                        "/file/download/*",
                        "/echarts/**",
                        "/blog/**",
                        "/test/**");
    }
}
